package org.example.forum.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.NonNull;
import org.example.forum.common.AppResult;
import org.example.forum.exception.ApplicationException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/test")
@Api(tags = "TestController 测试接⼝")
public class TestController {
    @RequestMapping("/hello")
    public String hello() {
        return "hello world";
    }
    @RequestMapping("/exception")
    public String exception() throws Exception {
        throw new Exception("这是一个Exception");
    }
    @RequestMapping("/applicationException")
    public String applicationException() throws ApplicationException {
        throw new ApplicationException("这是一个ApplicationException");
    }
    @ApiOperation("测试接口4，按传入的姓名显示你好信息")
    @PostMapping("/helloByName")
    public AppResult helloByName (@ApiParam(value = "姓名") @RequestParam("name") @NonNull String name) {
        return AppResult.success("hello : " + name);
    }
}
